package com.zhanglu.fun.services.datacenter.forumthread;

import com.zhanglu.fun.services.datacenter.entity.ForumThread;
import org.apache.commons.lang.StringUtils;

import java.util.Objects;

/**
 * @description 主题表查询sql
 * @author jing
 * @date 2017/9/3 0003 16:16
 */
public class ForumThreadProvider {

    public String selectForumThread(ForumThread forumThread) {
        StringBuilder sb = new StringBuilder();
        sb.append("select * from forum_thread ft where 1=1 ");
        if (null != forumThread && StringUtils.isNotEmpty(forumThread.getContent())) {
            sb.append("and (");
            sb.append("ft.title like CONCAT('%',#{content},'%') ");
            sb.append("or ft.content like  CONCAT('%',#{content},'%') ");
            sb.append("or ft.nick_name like CONCAT('%',#{content},'%') ");
            sb.append(") ");
        }
        if (null != forumThread && !Objects.isNull(forumThread.getThreadGroup()) && StringUtils.isNotEmpty(forumThread.getThreadGroup().toString())) {
            sb.append("and ft.thread_group = #{threadGroup}");
        }
        if (null != forumThread && !Objects.isNull(forumThread.getStatus()) && StringUtils.isNotEmpty(forumThread.getStatus().toString())) {
            sb.append("and ft.status = #{status}");
        }
        return sb.toString();
    }
}
